2020-2021 Sunseeker Telemetry and Lighting System
eusci_b_i2c_ex1_slaveTxMultiple.c
Go to the documentation of this file.
1 /* --COPYRIGHT--,BSD
2  * Copyright (c) 2017, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  * --/COPYRIGHT--*/
32 #include "driverlib.h"
33 
34 //*****************************************************************************
68 //
69 //*****************************************************************************
70 //*****************************************************************************
71 //
72 //Set the address for slave module. This is a 7-bit address sent in the
73 //following format:
74 //[A6:A5:A4:A3:A2:A1:A0:RS]
75 //
76 //A zero in the "RS" position of the first byte means that the master
77 //transmits (sends) data to the selected slave, and a one in this position
78 //means that the master receives data from the slave.
79 //
80 //*****************************************************************************
81 #define SLAVE_ADDRESS 0x48
82 
83 uint8_t TXData = 0;
84 
85 void main(void)
86 {
87  WDT_A_hold(WDT_A_BASE);
88 
89  // Configure Pins for I2C
90  //Set P1.6 and P1.7 as Secondary Module Function Input.
91  /*
92 
93  * Select Port 1
94  * Set Pin 6, 7 to input Secondary Module Function, (UCB0SIMO/UCB0SDA, UCB0SOMI/UCB0SCL).
95  */
96  GPIO_setAsPeripheralModuleFunctionInputPin(
97  GPIO_PORT_P1,
98  GPIO_PIN6 + GPIO_PIN7,
99  GPIO_SECONDARY_MODULE_FUNCTION
100  );
101 
102  EUSCI_B_I2C_initSlaveParam param = {0};
103  param.slaveAddress = 0x48;
104  param.slaveAddressOffset = EUSCI_B_I2C_OWN_ADDRESS_OFFSET0;
105  param.slaveOwnAddressEnable = EUSCI_B_I2C_OWN_ADDRESS_ENABLE;
106  EUSCI_B_I2C_initSlave(EUSCI_B0_BASE, &param);
107 
108  EUSCI_B_I2C_enable(EUSCI_B0_BASE);
109 
110  EUSCI_B_I2C_clearInterrupt(EUSCI_B0_BASE,
111  EUSCI_B_I2C_TRANSMIT_INTERRUPT0 +
112  EUSCI_B_I2C_STOP_INTERRUPT
113  );
114 
115  EUSCI_B_I2C_enableInterrupt(EUSCI_B0_BASE,
116  EUSCI_B_I2C_TRANSMIT_INTERRUPT0 +
117  EUSCI_B_I2C_STOP_INTERRUPT
118  );
119 
120  __bis_SR_register(CPUOFF + GIE); // Enter LPM0 w/ interrupts
121  __no_operation();
122 }
123 
124 
125 #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
126 #pragma vector=USCI_B0_VECTOR
127 __interrupt
128 #elif defined(__GNUC__)
129 __attribute__((interrupt(USCI_B0_VECTOR)))
130 #endif
131 void USCIB0_ISR(void)
132 
133 {
134 
135 switch(__even_in_range(UCB0IV,0x1E))
136  {
137  case 0x00: break; // Vector 0: No interrupts break;
138  case 0x02: break; // Vector 2: ALIFG
139  case 0x04: break; // Vector 4: NACKIFG
140  case 0x06: break; // Vector 6: STTIFG
141  case 0x08: // Vector 8: STPIFG
142  TXData = 0;
143  break;
144  case 0x0a: break; // Vector 10: RXIFG3 break;
145  case 0x0c: break; // Vector 14: TXIFG3 break;
146  case 0x0e: break; // Vector 16: RXIFG2 break;
147  case 0x10: break; // Vector 18: TXIFG2 break;
148  case 0x12: break; // Vector 20: RXIFG1 break;
149  case 0x14: break; // Vector 22: TXIFG1 break;
150  case 0x16: break; // Vector 24: RXIFG0 break;
151  case 0x18:
152  EUSCI_B_I2C_slavePutData(EUSCI_B0_BASE,
153  TXData++);
154  break; // Vector 26: TXIFG0 break;
155  case 0x1a: break; // Vector 28: BCNTIFG break;
156  case 0x1c: break; // Vector 30: clock low timeout break;
157  case 0x1e: break; // Vector 32: 9th bit break;
158  default: break;
159 
160  }
161 }
void USCIB0_ISR(void)
void main(void)
MPU_initThreeSegmentsParam param
__no_operation()